$().ready(function () {
    // Add a hint text to search form text input when the text input is empty
    // and has no focus.
    var $search = $('#search');
    var $label = $search.find('label[for="q"]').detach();
    var $input = $search.find('input[name="q"]');

    function removeHint() {
        if ($input.hasClass('hint')) {
            $input.val('').removeClass('hint');
        }
    }

    function addHint() {
        if (!$.trim($input.val())) {
            $input.val($label.text()).addClass('hint');
        }
    }

    $input.focus(removeHint).blur(addHint);

    addHint();

    $search.submit(removeHint);
});
